<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type="text/javascript">
$(document).ready(function () {
	$("#del").click(function() {
		if(confirm("삭제하시겠습니까?")){ 	
			$.ajax({
				type:"post",
				url:"deleteProduct.do",
				data:$("#delForm").serialize(),
				dataType:"json",
				success:function(jsonData){
					$("#productView").html("");
					var tbody="";
					$.each(jsonData,function(index,str){
						tbody+="<tr>";
						if(str.productAvailable==1){
							tbody+="<td><a href=updateProductView.do?productId="+str.productId+">"+str.productName+"</a></td>";
							tbody+="<td>"+str.productPrice+"</td><td>"+str.productDate+"</td>";
							tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td>"+str.inventoryVO.salesVolume+"</td>";
							tbody+="<td><input type='checkbox' id='productId' name='productId' value="+str.productId+"></td>";
						}//if 
						tbody+="</tr>";
					});   //each
					$("#productView").html(tbody);
				}//success
			});//ajax
		}//if
	});//click
	
	$("#orderByPrice").click(function(){
		$.ajax({
			type:"post",
			url:"orderByPrice.do",
			dataType:"json",
			success:function(jsonData){
				alert("가격대별 정렬입니다.");
				$("#productView").html("");
				var tbody="";
				$.each(jsonData,function(index,str){
					tbody+="<tr>";
					if(str.productAvailable==1){
						tbody+="<td><a href=updateProductView.do?productId="+str.productId+">"+str.productName+"</a></td>";
						tbody+="<td>"+str.productPrice+"</td><td>"+str.productDate+"</td>";
						tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td>"+str.inventoryVO.salesVolume+"</td>";
						tbody+="<td><input type='checkbox' id='productId' name='productId' value="+str.productId+"></td>";
					}//if 
					tbody+="</tr>";
				});   //each
				$("#productView").html(tbody);
			}//success
		});//ajax
	});
	
	$("#orderByDate").click(function(){
		$.ajax({
			type:"post",
			url:"orderByDate.do",
			dataType:"json",
			success:function(jsonData){
				alert("등록일시별 정렬입니다.");
				$("#productView").html("");
				var tbody="";
				$.each(jsonData,function(index,str){
					tbody+="<tr>";
					if(str.productAvailable==1){
						tbody+="<td><a href=updateProductView.do?productId="+str.productId+">"+str.productName+"</a></td>";
						tbody+="<td>"+str.productPrice+"</td><td>"+str.productDate+"</td>";
						tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td>"+str.inventoryVO.salesVolume+"</td>";
						tbody+="<td><input type='checkbox' id='productId' name='productId' value="+str.productId+"></td>";
					}//if 
					tbody+="</tr>";
				});   //each
				$("#productView").html(tbody);
			}//success
		});//ajax
	});
	
	$("#orderBySalesVolume").click(function(){
		$.ajax({
			type:"post",
			url:"orderBySalesVolume.do",
			dataType:"json",
			success:function(jsonData){
				alert("판매량별 정렬입니다.");
				$("#productView").html("");
				var tbody="";
				$.each(jsonData,function(index,str){
					tbody+="<tr>";
					if(str.productAvailable==1){
						tbody+="<td><a href=updateProductView.do?productId="+str.productId+">"+str.productName+"</a></td>";
						tbody+="<td>"+str.productPrice+"</td><td>"+str.productDate+"</td>";
						tbody+="<td>"+str.inventoryVO.inventoryAmount+"</td><td>"+str.inventoryVO.salesVolume+"</td>";
						tbody+="<td><input type='checkbox' id='productId' name='productId' value="+str.productId+"></td>";
					}//if 
					tbody+="</tr>";
				});   //each
				$("#productView").html(tbody);
			}//success
		});//ajax
	});
});//ready
</script>
</head>
<body>
<h3>${sessionScope.svo.sellerName }님의 판매물품내역입니다!</h3>
<input type="button" id="orderByPrice" value="가격대별정렬">
<input type="button" id="orderByDate" value="등록일시정렬">
<input type="button" id="orderBySalesVolume" value="판매량별정렬">
<br>
<form id="delForm">
<table border="1" cellpadding="5">
<thead>
	<tr>
		<th>상품이름</th>
		<th>상품가격</th><th>상품등록일시</th>
		<th>상품재고량</th><th>상품판매량</th><th>삭제</th>
	</tr>
</thead>
<tbody id="productView">
	<c:forEach items="${requestScope.list }" var="li">	
	<tr>
	<c:if test="${li.productAvailable==1}">
	<td><a href="updateProductView.do?productId=${li.productId}">${li.productName}</a></td><td>${li.productPrice}</td><td>${li.productDate}</td>
	<td>${li.inventoryVO.inventoryAmount}</td><td>${li.inventoryVO.salesVolume}</td>
	<td><input type="checkbox" id="productId" name="productId" value="${li.productId}"></td>
	</c:if>
	</tr>
	</c:forEach>
</tbody>
</table>
<input type="button" id="del" value="삭제하기" >
</form>
</body>
</html>